## @brief Enables interaction with the Console for App Engine
#  @author Ryan Brown, Michael Schick, Eli Perkins, Fahim Karim 

#!/usr/bin/python

import os
import code
import getpass
import sys
import optparse
import getpass

## Application specific
SDK_DIR = '/usr/local/google_appengine'
APP_DIR = './'

## Extra paths to be inserted into sys.path,
## including the SDK, it's libraries, your APPDIR, and APPDIR/lib
EXTRA_PATHS = [
	SDK_DIR,
    os.path.join(SDK_DIR, 'lib', 'antlr3'),
    os.path.join(SDK_DIR, 'lib', 'django_0_96'),
    os.path.join(SDK_DIR, 'lib', 'fancy_urllib'),
    os.path.join(SDK_DIR, 'lib', 'ipaddr'),
    os.path.join(SDK_DIR, 'lib', 'webob'),
    os.path.join(SDK_DIR, 'lib', 'yaml', 'lib'),
    os.path.join(SDK_DIR, 'lib', 'simplejson'),
    os.path.join(SDK_DIR, 'lib', 'graphy'),
	APP_DIR,
	os.path.join(APP_DIR, 'lib'),
]
sys.path = EXTRA_PATHS + sys.path

from google.appengine.ext.remote_api import remote_api_stub
from google.appengine.ext import db

def auth_func():
	if host and host.startswith('localhost'):
		return ('foo', 'bar')
	else:
		return (raw_input('Username: '), getpass.getpass())

if len(sys.argv) < 2:
    print "Usage: %s app_id [host]" % (sys.argv[0],)
app_id = sys.argv[1]
if len(sys.argv) > 2:
    host = sys.argv[2]
else:
    host = '%s.appspot.com' % app_id

remote_api_stub.ConfigureRemoteDatastore(app_id, '/remote_api', auth_func, host)

code.interact('App Engine interactive console', None, locals())